package day02;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/12 9:39
 * 二进制中1的个数
 */
public class Offer15 {

    public int hammingWeight(int n) {
        int sum = 0;
        while(n != 0) {
            // 按位与运算
            n = n & (n - 1);
            sum++;
        }
        return sum;
    }
}
